package com.chb.microservice.provider.hystrix;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cbh.api.model.ApiResult;
import com.chb.microservice.provider.feign.PaywayFeignClient;
import com.chb.microservice.provider.model.Payway;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class PaywayHystrixWrapped {

	@Autowired
	private PaywayFeignClient paywayFeignClient;

	/**
	 * 保存支付方式信息
	 * 
	 * @param product
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<String> save(Payway payway) {
		return paywayFeignClient.save(payway);
	};

	public ApiResult<String> fallBackCall(Payway payway) {
		return new ApiResult<String>().fail("调用出错");
	}

	/**
	 * 获取全部支付方式信息
	 * 
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<List<Payway>> getAll() {
		return paywayFeignClient.getAll();
	};

	public ApiResult<List<Payway>> fallBackCall() {
		return new ApiResult<List<Payway>>().fail("调用出错");
	}

	/**
	 * 获取支付方式信息
	 * 
	 * @param proId
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<Payway> getOne(String id) {
		return paywayFeignClient.getOne(id);
	};

	public ApiResult<Payway> fallBackCall(String id) {
		return new ApiResult<Payway>().fail("调用出错");
	}
}
